/*
 * @Description  : 管网分段信息
 * @Author       : zhao
 * @Date         : 2022-10-21 17:14:09
 * @LastEditors  : zhao
 * @LastEditTime : 2022-11-25 16:03:03
 */
import { findNodes, getPlSectionSection, addNode, updateNode, deleteNode, updateNodes, getSections, findSectionSections, findStations, findDevices, getRegion } from "@/api/piplineNodeInfo"
import { Message } from "element-ui"
import axios from 'axios'
const auction = {
    namespaced: true,
    state: {
        pipLineNodeInfoList: []
    },
    mutations: {

    },
    actions: {
        findNodes({ commit }, data) {
            return new Promise((resolve, reject) => {
//  console.log(data,'fffffffffffffffff')
                findNodes(data).then(res => {
                    if (res.code == "200") {
                        // Message.success(res.message)
                        resolve(res)
                    } else {
                        Message.error(res.message || "查询失败")
                        resolve(res)
                    }
                }).catch(error => {
                    resolve(error)
                })
            })
        },
        addNode({ commit }, data) {
            return new Promise((resolve, reject) => {
// console.log(data,'ddddddddddddddddddd')
                addNode(data).then(res => {
                    if (res.code == "200") {
                        Message.success(res.message || "添加成功")
                        resolve(res)
                    } else {
                        Message.error(res.message || "添加失败")
                        resolve(res)
                    }
                }).catch(error => {
                    resolve(error)
                })
            })
        },
        updateNode({ commit }, data) {
            return new Promise((resolve, reject) => {
// console.log(data,'uuuuuuuuuuuuuuu')
                updateNode(data).then(res => {
                    if (res.code == "200") {
                        Message.success(res.message || "更新成功")
                        resolve(res)
                    } else {
                        Message.error(res.message || "更新失败")
                        resolve(res)
                    }
                }).catch(error => {
                    resolve(error)
                })
            })
        },
        deleteNode({ commit }, data) {
            return new Promise((resolve, reject) => {

                deleteNode(data).then(res => {
                    if (res.code == "200") {
                        Message.success(res.message || "删除成功")
                        resolve(res)
                    } else {
                        Message.error(res.message || "删除失败")
                        resolve(res)
                    }
                }).catch(error => {
                    resolve(error)
                })
            })
        },
        findLineSections({ commit }, data) {
            return new Promise((resolve, reject) => {
 console.log(data,'ttttttttttttttttt')
                findSections(data).then(res => {
                    if (res.code == "200") {
                        resolve(res)
                    } else {
                        Message.error(res.message || "获取失败")
                        resolve(res)
                    }
                }).catch(error => {
                    resolve(error)
                })
            })
        },
        updateLineNodes({ commit }, data) {
            return new Promise((resolve, reject) => {
// console.log(data,'jjjjjjjjjjjjjjjjj')
                updateNodes(data.data,data.uuid).then(res => {
                    if (res.code == "200") {
                        Message.success(res.message || "更新节点成功")
                        resolve(res)
                    } else {
                        Message.error(res.message || "更新节点失败")
                        resolve(res)
                    }
                }).catch(error => {
                    resolve(error)
                })
            })
        },

        getLineSections({ commit }, data) {
            return new Promise((resolve, reject) => {

                getSections(data).then(res => {

                    
                    if (res.code == "200") {
                        resolve(res)
                    } else {
                        Message.error(res.message || "获取线段失败")
                        resolve(res)
                    }
                }).catch(error => {
                    resolve(error)
                })
            })
        },
        findStations({ commit }, data) {
            return new Promise((resolve, reject) => {

                findStations(data).then(res => {
                    if (res.code == "200") {
                        resolve(res)
                    } else {
                        Message.error(res.message || "获取厂站失败")
                        resolve(res)
                    }
                }).catch(error => {
                    resolve(error)
                })
            })
        },
        findDevices({ commit }, data) {
            return new Promise((resolve, reject) => {

                findDevices(data).then(res => {
                    if (res.code == "200") {
                        resolve(res)
                    } else {
                        Message.error(res.message || "获取附属设施失败")
                        resolve(res)
                    }
                }).catch(error => {
                    resolve(error)
                })
            })
        },
        findSectionSections({ commit }, data) {
            return new Promise((resolve, reject) => {
                // console.log(data,'iiiiiiiiiiiiiiiii')
                findSectionSections(data).then(res => {
                    if (res.code == "200") {
                        resolve(res)
                    } else {
                        Message.error(res.message || "获取附属设施失败")
                        resolve(res)
                    }
                }).catch(error => {
                    resolve(error)
                })
            })
        },
        getUserInfoApi() {
            getUserInfoApi()
        },
        getRegion({ commit }, data) {
            return new Promise((resolve, reject) => {

                getRegion(data).then(res => {
                    if (res.code == "200") {
                        resolve(res)
                    } else {
                        Message.error(res.message || "获取行政编码失败")
                        resolve(res)
                    }
                }).catch(error => {
                    resolve(error)
                })
            })
        },
        getMapJson({ commit, rootState }, data) {
            return new Promise((resolve, reject) => {
                axios({
                    method: "GET",
                    headers: {},
                    // url: `http://api.tianditu.gov.cn/administrative?postStr={"searchWord":"${data.data}","searchType":"${data.type}"}&tk=${rootState.map.key}`
                    url: 'https://restapi.amap.com/v3/config/district',
                    params: {
                        key: '46292e9153e0f3b81155ed3b24925d9a',
                        keywords: data.data,
                    }
                }).then(res => {
                    resolve(res)
                }).catch(err => {
                    resolve(err)

                })



            })
        },
        getPlSectionSection({ commit, rootState }, data) {
            return new Promise((resolve, reject) => {

                getPlSectionSection(data).then(res => {

                    if (res.code == "200") {
                        resolve(res)
                    } else {
                        Message.error(res.message || "获取管线信息失败")
                        resolve(res)
                    }
                }).catch(error => {
                    resolve(error)
                })
            })
        },
    },
};

export default auction;